package com.elvt.server.controller;


import com.elvt.server.pojo.Salary;
import com.elvt.server.service.ISalaryService;
import com.elvt.server.utils.RespSult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者：elvt
 * @since 2022-05-21
 */
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {
    @Autowired
    private ISalaryService salaryService;
    @ApiOperation(value = "获取所有工资账套")
    @GetMapping
    public List<Salary> findSalary(){
        return salaryService.list();

    }
    @ApiOperation(value = "添加工资账套")
    @PostMapping
    public RespSult saveSalary(@RequestBody Salary salary){
        salary.setCreateDate(LocalDateTime.now());
        if (salaryService.save(salary)){
            return RespSult.success("添加成功！");
        }
        return RespSult.error("添加失败！");

    }
    @ApiOperation(value = "删除工资账套")
    @DeleteMapping("/{id}")
    public RespSult deleteSalaryById(@PathVariable Integer id){
       if (salaryService.removeById(id)){
           return RespSult.success("删除成功！");
       }
       return RespSult.error("删除失败！");

    }
    @ApiOperation(value = "修改工资账套")
    @PutMapping
    public RespSult updateSalary(@RequestBody Salary salary){
        if (salaryService.updateById(salary)) {
            return RespSult.success("修改成功！");

        }
        return RespSult.error("修改失败");
    }

}
